package com.cn.kehong.controller;


import com.cn.kehong.api.IPlanYearService;
import com.cn.kehong.api.IPowRateService;
import com.cn.kehong.domain.PlanYear;
import com.cn.kehong.domain.PowRate;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/powRate")
public class PowRateController {

    @Autowired
    private IPowRateService powRateService;

    @RequestMapping("/getPowRateList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PowRate>> getPowRateList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<PowRate>> response = new JsonResponse<List<PowRate>>();
        List<PowRate> list  = powRateService.getPowRateList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }


    @ResponseBody
    @RequestMapping("/addPowRate/{frontToken}")
    public JsonResponse<String> addPowRate(@RequestBody PowRate powRate, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = powRateService.addPowRate(powRate);
        return CommonUtil.getResponseData(response,result);
    }


    @ResponseBody
    @RequestMapping("/updatePowRate/{frontToken}")
    public JsonResponse<String> updatePowRate(@RequestBody PowRate powRate, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = powRateService.updatePowRate(powRate);
        return CommonUtil.getResponseData(response,result);
    }



    @ResponseBody
    @RequestMapping("/deletePowRateById/{frontToken}")
    public JsonResponse<String> deletePowRateById(String id, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = powRateService.deletePowRateById(id);
        return CommonUtil.getResponseData(response,result);
    }


}
